<?php require VIEW_ROOT.'/common/header.php'?>

<style>
.stat_img { width:3px; cursor:pointer; margin:0; }
.amount_more { border-top:#06b 10px solid; }
.chart td { line-height:0px; padding:5px 5px 0 5px; }
.c1 td { background:url(./resource/images/finance/chart_bg1.gif) repeat-x bottom; }
.c2 td { background:url(./resource/images/finance/chart_bg2.gif) repeat-x bottom; }
.c3 td { background:url(./resource/images/finance/chart_bg3.gif) repeat-x bottom; }
.c4 td { background:url(./resource/images/finance/chart_bg4.gif) repeat-x bottom; }
#title { display:none; position:absolute; width:150px; background:#ffffc4; padding:5px; border:#698cc3 1px solid; filter:alpha(opacity=90); opacity:0.9; }
</style>
<script>
$(function() {
	body_height = $('body').height();
	$('.stat_img').hover(function(e) {
		var sleft = document.documentElement.scrollLeft + document.body.scrollLeft;
		var stop = document.documentElement.scrollTop + document.body.scrollTop;
		var title_obj = $("#title");
		title_obj.html($(this).attr('content'));
		y = stop + e.clientY + 20;
		x = sleft + e.clientX;
		(x + 150 > $(this).parent().width()) && (x -= 150);
		(y > body_height - 50) && (y -= 80);
		title_obj.css({top:y, left:x});
		title_obj.show();
	}, function() {
		$('#title').hide();
	});
});
</script>

<div id="title"></div>

<!--start.日均报表-->
<table class="chart c1">
	<tr>
		<th>日均支出报表 (-30,×3)</th>
	</tr>
	<tr>
		<td valign="bottom" style="height:200px;text-align:left;white-space:nowrap;">
			<?php foreach ($daily_stat as $key => $row) {?>
				<img 
					src="./resource/images/liteui/th_bg.gif" 
					style="height:<?php echo ($row['avg'] - 30) * 3?>px;"
					content="<?php echo date('Y / m / d', $key)?> <br> 当日：<?php echo $row['sum']?> <br> 日均：<?php echo $row['avg']?> <br> 趋势：<?php echo $row['avg_trend']?>"
					class="stat_img"
				/>
			<?php }?>
			<span style="color:#800;font-weight:bold;font-size:14px;">
				<?php echo empty($row['avg_trend']) ? 0 : ($row['avg_trend'] > 0 ? '+'.$row['avg_trend'] : '<span style="color:#080;">'.$row['avg_trend'].'</span>')?>
			</span>
		</td>
	</tr>
</table>
<!--end.日均报表-->

<!--start.去大额日均报表-->
<table class="chart c2">
	<tr>
		<th>日均支出报表 (去大额) (-30,×3)</th>
	</tr>
	<tr>
		<td valign="bottom" style="height:200px;text-align:left;white-space:nowrap;">
			<?php foreach ($daily_stat_lite as $key => $row) {?>
				<img 
					src="./resource/images/liteui/th_bg.gif" 
					style="height:<?php echo $row['avg']*3 - 90?>px;"
					content="<?php echo date('Y / m / d', $key)?> <br> 当日：<?php echo $row['sum']?> <br> 日均：<?php echo $row['avg']?> <br> 趋势：<?php echo $row['avg_trend']?>"
					class="stat_img"
				/>
			<?php }?>
			<span style="color:#800;font-weight:bold;font-size:14px;">
				<?php echo empty($row['avg_trend']) ? 0 : ($row['avg_trend'] > 0 ? '+'.$row['avg_trend'] : '<span style="color:#080;">'.$row['avg_trend'].'</span>')?>
			</span>
		</td>
	</tr>
</table>
<!--end.去大额日均报表-->

<!--start.30天日均报表(去大额)-->
<table class="chart c2">
	<tr>
		<th>30天日均支出报表 (去大额) (-30,×3)</th>
	</tr>
	<tr>
		<td valign="bottom" style="height:200px;text-align:left;white-space:nowrap;">
			<?php foreach ($daily_stat_lite as $key => $row) {?>
				<img 
					src="./resource/images/liteui/th_bg.gif" 
					style="height:<?php echo $row['avg_30']*3 - 90?>px;"
					content="<?php echo date('Y / m / d', $key)?> <br> 当日：<?php echo $row['sum']?> <br> 30天总计：<?php echo $row['sum_30']?> <br> 30天日均：<?php echo $row['avg_30']?>"
					class="stat_img"
				/>
			<?php }?>
			<span style="color:#800;font-weight:bold;font-size:14px;">
				<?php echo empty($row['avg_trend']) ? 0 : ($row['avg_trend'] > 0 ? '+'.$row['avg_trend'] : '<span style="color:#080;">'.$row['avg_trend'].'</span>')?>
			</span>
		</td>
	</tr>
</table>
<!--end.30天日均报表(去大额)-->

<!--start.总额报表-->
<table class="chart c3">
	<tr>
		<th>总额报表 (÷30)</th>
	</tr>
	<tr>
		<td valign="bottom" style="height:200px;text-align:left;white-space:nowrap;">
			<?php foreach ($daily_stat as $key => $row) {?>
				<img 
					src="./resource/images/liteui/th_bg.gif" 
					style="height:<?php echo $row['sum_all']/30?>px;"
					content="<?php echo date('Y / m / d', $key)?> <br> 当日：<?php echo $row['sum']?> <br> 日均：<?php echo $row['avg']?> <br> 总额：<?php echo $row['sum_all']?>"
					class="stat_img"
				/>
			<?php }?>
		</td>
	</tr>
</table>
<!--end.总额报表-->

<!--start.总额报表(去大额)-->
<table class="chart c3">
	<tr>
		<th>总额报表(去大额) (÷30)</th>
	</tr>
	<tr>
		<td valign="bottom" style="height:200px;text-align:left;white-space:nowrap;">
			<?php foreach ($daily_stat_lite as $key => $row) {?>
				<img 
					src="./resource/images/liteui/th_bg.gif" 
					style="height:<?php echo $row['sum_all']/30?>px;"
					content="<?php echo date('Y / m / d', $key)?> <br> 当日：<?php echo $row['sum']?> <br> 日均：<?php echo $row['avg']?> <br> 总额：<?php echo $row['sum_all']?>"
					class="stat_img"
				/>
			<?php }?>
		</td>
	</tr>
</table>
<!--end.总额报表(去大额)-->

<!--start.每日报表-->
<table class="chart c4">
	<tr>
		<th>每日支出报表 (÷2)</th>
	</tr>
	<tr>
		<td valign="bottom" style="height:200px;text-align:left;white-space:nowrap;">
			<?php foreach ($daily_stat as $key => $row) {?>
				<img 
					src="./resource/images/liteui/th_bg.gif" 
					style="height:<?php echo $row['sum'] <= 300 ? $row['sum']/2 : 150 + ($row['sum']-300)/20?>px;"
					class="stat_img<?php echo $row['sum'] <= 300 ? '' : ' amount_more'?>"
					content="<?php echo date('Y / m / d', $key)?> <br> 当日：<?php echo $row['sum']?> <br> 日均：<?php echo $row['avg']?>"
				/>
			<?php }?>
		</td>
	</tr>
</table>
<!--end.每日报表-->

<?php
include("resource/pchart/pData.class.php");   
include("resource/pchart/pChart.class.php");   

//print_r($daily_stat);
$data = array();
$label = array();
$now = time();
foreach ($daily_stat_lite as $key => $row) {
	if($key < $now - 86400 * 50) {
		continue;
	}
	$data[] = $row['avg'];
	$label[] = date('j', $key);
	// $data[$row['date']] = $row['hits'];
}

// (1)数据  
$DataSet = new pData();
$DataSet->AddPoint($data, "Serie1");
//$DataSet->AddPoint($hour_data_final2, "Serie2");
$DataSet->AddPoint($label, "Serie3");
$DataSet->AddSerie('Serie1');  
//$DataSet->AddSerie('Serie2');  
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("50 Days", "Serie1");   
//$DataSet->SetSerieName("Today","Serie2");   
$DataSet->SetYAxisName("RMB");
$DataSet->SetXAxisName("Date");

// (2)图表
$Test = new pChart(1000,255);
$Test->setFontProperties("resource/fonts/tahoma.ttf",8);   
$Test->setGraphArea(70,30,980,210); 
$Test->drawFilledRoundedRectangle(7,7,993,248,5,240,240,240);   
$Test->drawRoundedRectangle(5,5,695,250,5,230,230,230); 
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);   
$Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line
$Test->setFontProperties("resource/fonts/tahoma.ttf",6);   
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());   
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

// (3)显示
$Test->setFontProperties("resource/fonts/tahoma.ttf",8);   
$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255);   
$Test->setFontProperties("resource/fonts/tahoma.ttf",10);   
$Test->drawTitle(60,22,"50 Days",50,50,50,785); 
$img_filename = 'resource/chart/payout_per_day.png';
$Test->Render($img_filename);
echo '<table><tr><th>50天日均支出图(去大额)</th></tr> <tr><td style="background:#ffffff;text-align:left;"><img src="'.$img_filename.'"></td></tr></table>';
?>

<?php require VIEW_ROOT.'/common/footer.php'?>
